package com.designpattern.obeserver.method2;

import java.util.Observable;
import java.util.Observer;

/**
 * @author: guoqiang.lv
 * @date: 2019/6/18
 * @description:
 */
public class CurrentConditionsDisplay implements DisplayElement, Observer {

    private float temperature;

    private Observable observable;

    public CurrentConditionsDisplay(Observable observable) {
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void display() {
        System.out.println("CurrentConditionsDisplay 温度: " + temperature);
    }

    @Override
    public void update(Observable subject, Object arg) {
        if (subject instanceof WeatherData) {
            this.temperature = ((WeatherData) subject).getTemperature();
            display();
        }
    }
}
